package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

@Controller
public class TestController {
    @Autowired
    private IUserService service;

    @RequestMapping("/abc")
    @ResponseBody
    public String add(){
        return "<h1 style='color:red'>执行添加</h1>";
    }

//    @RequestMapping("/abc")
//    public void add(HttpServletResponse response) throws Exception{
//       response.getWriter().print("执行添加");
//    }

    @RequestMapping("/register")
    public String registerUser(UserBean user,int price,@RequestParam("name") String userName){
        System.out.println(user+"    "+price+"    "+userName);
        System.out.println("执行业务方法，结果："+service.getInfo());
        return "redirect:/bean";
    }

    @RequestMapping("/bean")
    @ResponseBody
    public UserBean getBean(){
        return new UserBean(1,"张三","24324324324",9000, LocalDate.parse("1998-02-03"));
    }
}
